package com.casa_apoio.model.dao;

import com.casa_apoio.model.entity.Hospede;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

public class HospedeDAO<T> extends HibernateDAO<T> {

    public HospedeDAO(Class<T> classe, Session session) {
        super(classe, session);
    }

    public List<Hospede> listaHospedePorNome() {
        Criteria criterio = criaCriteria();
        criterio.addOrder(Order.asc("nome")).setMaxResults(4);
        List<Hospede> lista = criterio.list();
        return lista;
    }

    public List<Hospede> pesquisarHospede(String value) {
        Criterion filtro = Restrictions.like("nome", value + "%");
        Criteria criterio = criaCriteria();
        criterio.addOrder(Order.asc("nome")).setMaxResults(8).add(filtro);
        List<Hospede> lista = criterio.list();
        return lista;
    }

    public List<T> buscarHospedePorCPF(String value) {
        Criterion filtro = Restrictions.eq("cpf", value);
        Criteria criterio = criaCriteria();
        criterio.add(filtro);
        List<T> lista = criterio.list();
        return lista;
    }

}
